package org.monitor.servlet.router;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.monitor.servlet.base.Resource;

public class ActionMappings {
	
	private static Logger logger = Logger.getLogger("action mappings");
	
	private Map<String, Action> actionMap = new HashMap<String, Action>();
	

	public Action getAction(Resource res){
		Action action = actionMap.get(res.getResource());
		if(action != null){
			return action;
		}
		return null;
	}
	
	ActionMappings addAction(String actionKey, Action action){
		if(actionMap.containsKey(actionKey)){
			throw new RuntimeException("actionKey[" + actionKey + "] has exists!");
		}
		logger.log(Level.INFO, actionKey);
		
		actionMap.put(actionKey, action);
		return this;
	}
}
